import React from 'react'
import Son from "./components/Son";

class App extends React.Component {
    state = {
        count: 1,
        msg: 'atguigu'
    }
    // 1. 父组件中定义方法
    addCount(num){
        console.log('num: ', num);
        this.setState({
            count: this.state.count + num
        })
    }
    render() {
        let {count, msg} = this.state;
        return (
            <>
                <h3>App</h3>
                <p>state count: {count}</p>
                <p>state msg: {msg}</p>
                <p><button onClick={()=>{
                    this.setState({
                        count: 100
                    })
                }}>count++</button></p>
                <hr />
                {/**2. 通过标签属性将方法传递给子组件 */}
                <Son count={count} msg={msg} school='尚硅谷' addCount={this.addCount.bind(this)}/>
            </>
        );
    }

}
export default App;
